<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\CategorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

//$this->title = 'Categories';
$this->title = backend\models\Category::getCTableName() . '管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="category-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('添加' . $this->title, ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?=
    GridView::widget([
        'dataProvider' => $dataProvider,
//        'filterModel' => $searchModel,
        'columns' => [
                ['class' => 'yii\grid\SerialColumn'],
//            'categoryId',
//            'title',
            ["attribute" => "title",
                'value' => function ($data) {
                    return Html::a(\backend\models\Category::getCategoryList_S()["$data->categoryId"], ['category/view', "id" => $data->categoryId]);
                },
                'format' => 'raw',
            ],
            'createTime',
//            'parentId',
            ["attribute" => "parentId",
                'value' => function ($data) {
                    $categoryList = \backend\models\Category::getCategoryList_S();
                    if ($data->parentId != 0) {
                        return Html::a($categoryList["$data->parentId"], ['category/view', "id" => $data->parentId]);
                    } else {
                        return $categoryList["$data->parentId"];
                    }
                },
                'format' => 'raw',
            ],
                ['class' => 'yii\grid\ActionColumn'],
        ],
    ]);
    ?>
</div>
